package utils;

import entity.Account;
import entity.CreateAccountDTO;
import entity.CreateAccountVO;
import entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author tanghailan
 * @date 2022-01-18 16:14:19
 * @description
 */
@Mapper
public interface AccountConvertUtils {
  AccountConvertUtils INSTANCE = Mappers.getMapper(AccountConvertUtils.class);

  // 普通的映射
  CreateAccountVO convert(CreateAccountDTO createAccountDTO);

  // 复制一份
  List<Account> copy(List<Account> account);

  // 类型转换的映射
  @Mappings({
    @Mapping(target = "visitKey", source = "key"),
  })
  CreateAccountVO convertWithMapping(CreateAccountDTO createAccountDTO);

  // 多对一映射
  @Mappings({
    @Mapping(target = "visitKey", source = "createAccountDTO.key"),
  })
  CreateAccountVO convert(User user, CreateAccountDTO createAccountDTO);
}
